<?php 
	$_currentBrandId = $this->getRequest()->getParam('brand', false);
	$_category = $this->getCurrentCategory();
	$limit = $this->getRequest()->getParam('limit', false);
	$_productCollection = $this->getProductCollection($limit);
	$_helper = $this->helper('catalog/output');
	$zgbHelper = Mage::helper('zgb');
	$newIds = array();
	$cataId = 0;
 ?>
<div  class="row main">
	<ul class="breadcrumbs">
		<li>
			<a href="<?php echo Mage::getBaseurl() ?>" title="前往主页">主页</a>
			<span>></span>
		</li>
		<li>
			<strong>
			<?php 
				if(strstr(Mage::helper('core/url')->getCurrentUrl(), '/catalogsearch/result/'))
				{
					echo "搜索结果";
				}else{
					echo $_category->getName();
				}
			?>
			</strong>
		</li>
	</ul>

	<div class="product-screen">
			<?php if($this->getKeyword()): ?>
			<div class="serach-keywords">
				<p>"<?php echo $this->getKeyword()?>"的搜索结果</p>
			</div>
			<?php endif ?>
			<div class="nav">
				<?php if(!strstr(Mage::helper('core/url')->getCurrentUrl(), '/catalogsearch/result/')): ?>
					<div class="row title">
						<h3>商品筛选:</h3>
						<h4><a href="/index.php/admin_zgb/recent/index/">最近购买</a></h4>
					</div>
					
					<div  class="row nav-section">
						<span>已筛选:</span>
						<?php 
							$cataId = $_category->getId();
							$layerCatagory = $this->getLayerForCatagory($cataId)
						 ?>
						<ul>
							<?php if(intval($_category->getId()) !== 12): ?>
							<li class="layer-li-styles">
								<?php echo $_category->getName() ?>
								<a href="<?php echo $layerCatagory->getUrl()?>">
									<?php echo $this->__('删除') ?>
								</a>
							</li>
							<?php endif; ?>
							<?php if($_currentBrandId):?>
								<li class="layer-li-styles">
									<?php echo $this->getBrandName($_currentBrandId);;?>
									<a href="<?php echo $_category->getUrl()?>">
										<?php echo $this->__('删除') ?>
									</a>
								</li>
							<?php endif;?>
						</ul>
					</div>
					<?php if(count($_category->getChildrenCategories()) > 0): ?>
					<div class="row nav-section">
						<span>分类:</span>
						<ul>  
							<?php foreach($_category->getChildrenCategories() as $layerCata): ?>
								<li><a href="<?php echo $layerCata->getUrl() ?>"><?php echo $layerCata->getName() ?></a></li>
							<?php endforeach; ?>
						</ul>
					</div>
					<?php endif; ?>
					<?php $brands = $this->getBrands(); ?>
					<?php if($brands && !$_currentBrandId):?>
					<div class="row nav-section">
						<span>品牌:</span>
						<ul>
							<?php foreach($brands as $brand):?>
								<li><a href="<?php echo $_category->getUrl(); ?>?brand=<?php echo $brand['id']?>"><?php echo $brand['name']; ?></a></li>
							<?php endforeach;?>
						</ul>
					</div>
					<?php endif;?>
				<?php endif; ?>

 <?php if(!$_productCollection->count()): ?>
 	<p class="note-msg"><?php echo $this->__('此分类下还没有任何产品或者产品还未上架!!!请等待商品上架...'); ?></p>
 <?php else : ?>

				<div class="line"></div>
				<div class="row product-section">
					<strong>商品列表</strong>
					<div class=" row pager">
						<div class="row select-area">
							<div class="sort">
								<label>排序:</label>
								<select onchange="setLocation(this.value)">
									<?php foreach($this->getAvailableOrders() as $_order): ?>
						                <option value="<?php echo Mage::helper('core/url')->getCurrentUrl() . '?' . $_order['url'] ?>">
						                    <?php echo $_order['name'] ?>
						                </option>
						            <?php endforeach; ?>
								</select>
								<?php 
					            	$descAscinfo = $this->getCurrentDirection($_category->getId());
					             ?>
					            <?php if($descAscinfo['dir'] == 'desc'): ?>
					                <a href="<?php echo $descAscinfo['url'] ?>" title="<?php echo $descAscinfo['title']; ?>">
					                	<img src="<?php echo $this->getSkinUrl('images/i_desc_arrow.gif') ?>" alt="<?php echo Mage::helper('core')->quoteEscape($this->__('Set Ascending Direction')) ?>" class="v-middle" />
					                </a>
					            <?php else: ?>
					                <a href="<?php echo $descAscinfo['url'] ?>">
					                	<img src="<?php echo $this->getSkinUrl('images/i_asc_arrow.gif') ?>" alt="<?php echo Mage::helper('core')->quoteEscape($this->__('Set Descending Direction')) ?>" class="v-middle" />
					                	</a>
					            <?php endif; ?>
							</div>
							<div class="amount">
								<label>显示:</label>
								<select onchange="setLocation(this.value)">
									<?php foreach($this->getAvailableLimit($_category->getId()) as $limits): ?>
									<option <?php if($limit == $limits['limit']) : ?>selected="selected"<?php endif;?> value="<?php echo $limits['url'] ?>"><?php echo $limits['limit'] ?></option>
									<?php endforeach; ?>
								</select>
							</div>
						</div>
						<ul class="row pagination">
							<?php echo $this->getPagerHtml($this->getRequest()->getParam('limit')); ?>
						</ul>
					</div>

					<div class="line"></div>

					<?php $currentPage = $this->getRequest()->getParam('page', false); ?>

					<ul class="product-list">
						<?php if($_category->getId() == 12 && !strstr(Mage::helper('core/url')->getCurrentUrl(), '/catalogsearch/result/') && $currentPage == 1): ?>
							<?php foreach($this->getNewProductForOne() as $_product): ?>
							<?php $newIds[] = $_product->getId(); ?>
							<li>
								<div class="product-wrap">
									<div class="product-image">
										<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
											<img class="lazy" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(210); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"/>
										</a>
										<?php if($zgbHelper->hasTag($_product)): ?>
											<div class="product-sale-tag">
												<img src="<?php echo $zgbHelper->getSaleTagUrl($_product, $this->getSkinUrl('images')); ?>" alt="">
											</div>
										<?php endif; ?>
									</div>
									<div class="product-shop">
										<h3><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h3>
										<span class="product-list-datetimes">
						                    <?php 
						                    	if($_product->getPromotion())
						                    	{
						                    		echo $_product->getPromotion();
						                    	}else{
						                    		echo '&nbsp';
						                    	}
						                     ?>
					                    </span>
					                    <div class="product-shop">
											<div class="row">
												 <?php if(number_format($_product->getPrice(),2) <= number_format($_product->getFinalPrice(),2)): ?>
													<span class="col-2 special-price">
									                    ￥&nbsp;<?php echo number_format($_product->getPrice(),2); ?>
									                </span>
									            <?php else : ?>
									                <span class="col-2 old-price" >
		                                                ￥&nbsp;<?php echo number_format($_product->getPrice(),2); ?>
									                </span>
									                <span class="col-2 special-price">
									                    ￥&nbsp;<?php echo number_format($_product->getFinalPrice(),2); ?>
									                </span>
									            <?php endif; ?>
											</div>
										</div>
										<div class="row fill-box" id="datactions" data-action="<?php echo $this->getUrl('checkout/cart/addAjax',array('product'=>$_product->getId())); ?>">
											<div class="col-2 qty-area">
												<span class="reduce">-</span>
												<div class="qty-input">
													<input type="text" name="qty" id="qty" value="1"/>
												</div>
												<span class="add">+</span>
											</div>
											<div class="col-2">
												<button class="add-cart-button">加入购物车</button>
											</div>
										</div>
									</div>
								</div>
							</li>
							<?php endforeach; ?>
						<?php endif; ?>
						<?php foreach($_productCollection as $_product): ?>
						<?php if(in_array($_product->getId(),$newIds)) continue;?>
						<li>
								<div class="product-wrap">
									<div class="product-image">
										<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
											<img class="lazy" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(210); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"/>
										</a>
										<?php if($zgbHelper->hasTag($_product)): ?>
											<div class="product-sale-tag">
												<img src="<?php echo $zgbHelper->getSaleTagUrl($_product, $this->getSkinUrl('images')); ?>" alt="">
											</div>
										<?php endif; ?>
									</div>
									<div class="product-shop">
										<h3><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h3>
					                    <span class="product-list-datetimes">
						                    <?php 
						                    	if($_product->getPromotion())
						                    	{
						                    		echo $_product->getPromotion();
						                    	}else{
						                    		echo '&nbsp';
						                    	}
						                     ?>
					                    </span>
										<div class="product-shop">
												<div class="row">
													 <?php if(number_format($_product->getPrice(),2) <= number_format($_product->getFinalPrice(),2)): ?>
														<span class="col-2 special-price">
										                    ￥&nbsp;<?php echo number_format($_product->getPrice(),2); ?>
										                </span>
										            <?php else : ?>
										                <span class="col-2 old-price" >
			                                                ￥&nbsp;<?php echo number_format($_product->getPrice(),2); ?>
										                </span>
										                <span class="col-2 special-price">
										                    ￥&nbsp;<?php echo number_format($_product->getFinalPrice(),2); ?>
										                </span>
										            <?php endif; ?>
												</div>
											</div>
										<div class="row fill-box" id="datactions" data-action="<?php echo $this->getUrl('checkout/cart/addAjax',array('product'=>$_product->getId())); ?>">
											<div class="col-2 qty-area">
												<span class="reduce">-</span>
												<div class="qty-input">
													<input type="text" name="qty" id="qty" value="1"/>
												</div>
												<span class="add">+</span>
											</div>
											<div class="col-2">
												<button class="add-cart-button">加入购物车</button>
											</div>
										</div>
									</div>
								</div>
						</li>
					<?php endforeach; ?>
					</ul>

					<div class=" row pager">
						<div class="row select-area">
							<div class="sort">
								<label>排序:</label>
								<select onchange="setLocation(this.value)">
									<?php foreach($this->getAvailableOrders() as $_order): ?>
						                <option value="<?php echo Mage::helper('core/url')->getCurrentUrl() . '?' . $_order['url'] ?>">
						                    <?php echo $_order['name'] ?>
						                </option>
						            <?php endforeach; ?>
								</select>
								<?php 
					            	$descAscinfo = $this->getCurrentDirection($cataId);
					             ?>
					            <?php if($descAscinfo['dir'] == 'desc'): ?>
					                <a href="<?php echo $descAscinfo['url'] ?>" title="<?php echo $descAscinfo['title']; ?>">
					                	<img src="<?php echo $this->getSkinUrl('images/i_desc_arrow.gif') ?>" alt="<?php echo Mage::helper('core')->quoteEscape($this->__('Set Ascending Direction')) ?>" class="v-middle" />
					                </a>
					            <?php else: ?>
					                <a href="<?php echo $descAscinfo['url'] ?>">
					                	<img src="<?php echo $this->getSkinUrl('images/i_asc_arrow.gif') ?>" alt="<?php echo Mage::helper('core')->quoteEscape($this->__('Set Descending Direction')) ?>" class="v-middle" />
					                	</a>
					            <?php endif; ?>
							</div>
							<div class="amount">
								<label>显示:</label>
								<select onchange="setLocation(this.value)">
									<?php foreach($this->getAvailableLimit($cataId) as $limits): ?>
									<option <?php if($limit == $limits['limit']) : ?>selected="selected"<?php endif;?> value="<?php echo $limits['url'] ?>"><?php echo $limits['limit'] ?></option>
									<?php endforeach; ?>
								</select>
							</div>
						</div>
						<ul class="row pagination">
							<?php echo $this->getPagerHtml(); ?>
						</ul>
					</div>
				</div>
				<?php endif; ?>
				<div class="line"></div>
			</div>
	</div>
</div>